<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include "../connection/connection.php";
if ( !isset($_GET['pages'] ))
	{
    	$page = 1 ;
	}else{
		$page = $_GET['pages'] ;
}
	
	$searchcurrent = $_REQUEST['searchcurrent'];	
	$searchlast7day = $_REQUEST['searchlast7day'];
	
	$search = $_REQUEST['search'];
	$rows_per_page = 20;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	
	$selectlogserver = mysql_query("SELECT ls.*,ui.email FROM `user_info` ui, log_server ls WHERE ls.id = ui.id and ls.ins_time >='".$searchlast7day." 00:00:00' and ls.ins_time<='".$searchcurrent." 23:59:59' ORDER BY ls.ins_time ASC");
	$number_of_page = ceil ( mysql_num_rows( $selectlogserver ) / $rows_per_page ); 
?>
			<?php
			if(mysql_num_rows($selectlogserver)>0){
				$i=0;
				while ($row = mysql_fetch_array($selectlogserver)){
					if ( $i >= $page_start ){?>
				<tr>
						<td align="center" style="width:4%;background: white;color: #5D5D5D;font-weight: normal;"><?php echo $i+1?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[email] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[server_ip] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[server_name]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[version]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[status]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[server_time]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[ins_time]?></td>
					</tr>
			<?php
					}
						$i++;
						if ($i >= $page_end){
							break;
						}
					}
				}
			?>
			
			<tr>
						<td colspan="8" class="rf-dt-shdr-c">
							<span style="padding:1px; display: inline-block;">
														
								<?php if ( $number_of_page > 1 ) 
								{ 
									if ($page==1)
										$p=2;
									else if ($page==$number_of_page)
										$p=$number_of_page-1;
									else $p=$page;
									if($page!=1){?>
										<a onclick="pagingsearchBy7Day(<?=1?>,'<?=$search?>','<?=$searchcurrent?>','<?=$searchlast7day?>')"><span class='button_next'><?php echo "<<<";?></span> </a>
										<a onclick="pagingsearchBy7Day(<?=($page-1)?>,'<?=$search?>','<?=$searchcurrent?>','<?=$searchlast7day?>')"><span class='button_next'><?php echo "<<";?></span> </a>
									<?php  }
									else{
										echo "<span class='button_next'><<<</span> "; 
										echo "<span class='button_next'><<</span> ";
									}
									for ( $i = $p-1; $i <= $p+1; $i++ ) {	
											if ($i<=$number_of_page && $i>0)
											
												if ($i==$page){
													echo "<span class='button_next'><b>".$i."</b></span>"; 
												}else{
												?>
													<a onclick="pagingsearchBy7Day(<?=$i?>,'<?=$search?>','<?=$searchcurrent?>','<?=$searchlast7day?>')"><span class="button_next">
													<?php 
													echo $i;
													?>
													</span> </a>
													<?php 
												}
											?>
										
									<?php 
											}
										
										if($page!=$number_of_page){ ?>
											<a onclick="pagingsearchBy7Day(<?=($page+1)?>,'<?=$search?>','<?=$searchcurrent?>','<?=$searchlast7day?>')"><span class='button_next'><?php echo ">>";?></span> </a>
											<a onclick="pagingsearchBy7Day(<?=($number_of_page)?>,'<?=$search?>','<?=$searchcurrent?>','<?=$searchlast7day?>')"><span class='button_next'><?php echo ">>>";?></span> </a>
										<?php }
										else{
											echo "<span class='button_next'>>></span> ";
											echo "<span class='button_next'>>>></span> ";
										}
									}
								
									
									?>
																						
							</span>
						</td>
					</tr>